/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using SES.CMS.DO;
/// <summary>
/// Summary description for cmsSanPhamDAL
/// </summary>
namespace SES.CMS.DAL
{

    public class cmsSanPhamDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsSanPhamDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion

        //dfgsdfgfsdf/

        #region Public Methods
        public int Insert(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@MaSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.MaSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TenSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.TenSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Mota", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.Mota;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTaChiTiet", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.MoTaChiTiet;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@BaoHanh", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.BaoHanh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.LoaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NhanHieuID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.NhanHieuID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TuKhoa", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.TuKhoa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HinhAnh", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.HinhAnh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DonGia", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.DonGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@GiamGia", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.GiamGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SanPhamMoi", SqlDbType.Bit);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamMoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SanPhamBanChay", SqlDbType.Bit);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamBanChay;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DonViID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.DonViID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@XuatXuID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.XuatXuID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@SanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MaSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.MaSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TenSanPham", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.TenSanPham;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTa", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.Mota;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@MoTaChiTiet", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.MoTaChiTiet;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@BaoHanh", SqlDbType.NText);
            Sqlparam.Value = objcmsSanPhamDO.BaoHanh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.LoaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@NhanHieuID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.NhanHieuID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@TuKhoa", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.TuKhoa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HinhAnh", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSanPhamDO.HinhAnh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DonGia", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.DonGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@GiamGia", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.GiamGia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SanPhamMoi", SqlDbType.Bit);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamMoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SanPhamBanChay", SqlDbType.Bit);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamBanChay;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DonViID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.DonViID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@XuatXuID", SqlDbType.Int);
            Sqlparam.Value = objcmsSanPhamDO.XuatXuID;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@SanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public void UpdateAll(int stt,int[] spid,long[] dongia)
        {
            SqlCommand SqlComm = new SqlCommand();
            SqlComm.CommandType = CommandType.Text;
            string s = "";
            for (int i = 0; i < stt; i++)
            {
                s += "Update cmsSanPham set DonGia= " + dongia[i] + " where SanPhamID=" + spid[i] + " ";
            }
            SqlComm.CommandText = s;

            base.ExecuteNoneQuery(SqlComm);
        }

        public cmsSanPhamDO Select(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@SanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["SanPhamID"]))
                    objcmsSanPhamDO.SanPhamID = Convert.ToInt64(dr["SanPhamID"]);
                if (!Convert.IsDBNull(dr["MaSanPham"]))
                    objcmsSanPhamDO.MaSanPham = Convert.ToString(dr["MaSanPham"]);
                if (!Convert.IsDBNull(dr["TenSanPham"]))
                    objcmsSanPhamDO.TenSanPham = Convert.ToString(dr["TenSanPham"]);
                if (!Convert.IsDBNull(dr["Mota"]))
                    objcmsSanPhamDO.Mota = Convert.ToString(dr["Mota"]);
                if (!Convert.IsDBNull(dr["MoTaChiTiet"]))
                    objcmsSanPhamDO.MoTaChiTiet = Convert.ToString(dr["MoTaChiTiet"]);
                if (!Convert.IsDBNull(dr["BaoHanh"]))
                    objcmsSanPhamDO.BaoHanh = Convert.ToString(dr["BaoHanh"]);
                if (!Convert.IsDBNull(dr["LoaiSanPhamID"]))
                    objcmsSanPhamDO.LoaiSanPhamID = Convert.ToInt32(dr["LoaiSanPhamID"]);
                if (!Convert.IsDBNull(dr["NhanHieuID"]))
                    objcmsSanPhamDO.NhanHieuID = Convert.ToInt32(dr["NhanHieuID"]);
                if (!Convert.IsDBNull(dr["TuKhoa"]))
                    objcmsSanPhamDO.TuKhoa = Convert.ToString(dr["TuKhoa"]);
                if (!Convert.IsDBNull(dr["HinhAnh"]))
                    objcmsSanPhamDO.HinhAnh = Convert.ToString(dr["HinhAnh"]);
                if (!Convert.IsDBNull(dr["DonGia"]))
                    objcmsSanPhamDO.DonGia = Convert.ToInt64(dr["DonGia"]);
                if (!Convert.IsDBNull(dr["GiamGia"]))
                    objcmsSanPhamDO.GiamGia = Convert.ToInt64(dr["GiamGia"]);
                if (!Convert.IsDBNull(dr["SanPhamMoi"]))
                    objcmsSanPhamDO.SanPhamMoi = Convert.ToBoolean(dr["SanPhamMoi"]);
                if (!Convert.IsDBNull(dr["SanPhamBanChay"]))
                    objcmsSanPhamDO.SanPhamBanChay = Convert.ToBoolean(dr["SanPhamBanChay"]);
                if (!Convert.IsDBNull(dr["DonViID"]))
                    objcmsSanPhamDO.DonViID = Convert.ToInt32(dr["DonViID"]);
                if (!Convert.IsDBNull(dr["XuatXuID"]))
                    objcmsSanPhamDO.XuatXuID = Convert.ToInt32(dr["XuatXuID"]);


            }
            return objcmsSanPhamDO;
        }
        public cmsSanPhamDO SelectByMaSP(string ma)
        {
            cmsSanPhamDO objcmsSanPhamDO = new cmsSanPhamDO();
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_getByMaSP";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ma", SqlDbType.NVarChar);
            Sqlparam.Value = ma;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["SanPhamID"]))
                    objcmsSanPhamDO.SanPhamID = Convert.ToInt64(dr["SanPhamID"]);
                if (!Convert.IsDBNull(dr["MaSanPham"]))
                    objcmsSanPhamDO.MaSanPham = Convert.ToString(dr["MaSanPham"]);
                if (!Convert.IsDBNull(dr["TenSanPham"]))
                    objcmsSanPhamDO.TenSanPham = Convert.ToString(dr["TenSanPham"]);
                if (!Convert.IsDBNull(dr["Mota"]))
                    objcmsSanPhamDO.Mota = Convert.ToString(dr["Mota"]);
                if (!Convert.IsDBNull(dr["MoTaChiTiet"]))
                    objcmsSanPhamDO.MoTaChiTiet = Convert.ToString(dr["MoTaChiTiet"]);
                if (!Convert.IsDBNull(dr["BaoHanh"]))
                    objcmsSanPhamDO.BaoHanh = Convert.ToString(dr["BaoHanh"]);
                if (!Convert.IsDBNull(dr["LoaiSanPhamID"]))
                    objcmsSanPhamDO.LoaiSanPhamID = Convert.ToInt32(dr["LoaiSanPhamID"]);
                if (!Convert.IsDBNull(dr["NhanHieuID"]))
                    objcmsSanPhamDO.NhanHieuID = Convert.ToInt32(dr["NhanHieuID"]);
                if (!Convert.IsDBNull(dr["TuKhoa"]))
                    objcmsSanPhamDO.TuKhoa = Convert.ToString(dr["TuKhoa"]);
                if (!Convert.IsDBNull(dr["HinhAnh"]))
                    objcmsSanPhamDO.HinhAnh = Convert.ToString(dr["HinhAnh"]);
                if (!Convert.IsDBNull(dr["DonGia"]))
                    objcmsSanPhamDO.DonGia = Convert.ToInt64(dr["DonGia"]);
                if (!Convert.IsDBNull(dr["GiamGia"]))
                    objcmsSanPhamDO.GiamGia = Convert.ToInt64(dr["GiamGia"]);
                if (!Convert.IsDBNull(dr["SanPhamMoi"]))
                    objcmsSanPhamDO.SanPhamMoi = Convert.ToBoolean(dr["SanPhamMoi"]);
                if (!Convert.IsDBNull(dr["SanPhamBanChay"]))
                    objcmsSanPhamDO.SanPhamBanChay = Convert.ToBoolean(dr["SanPhamBanChay"]);
                if (!Convert.IsDBNull(dr["DonViID"]))
                    objcmsSanPhamDO.DonViID = Convert.ToInt32(dr["DonViID"]);
                if (!Convert.IsDBNull(dr["XuatXuID"]))
                    objcmsSanPhamDO.XuatXuID = Convert.ToInt32(dr["XuatXuID"]);


            }
            return objcmsSanPhamDO;
        }

		public DataTable SelectByID(cmsSanPhamDO objcmsSanPhamDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@SanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = objcmsSanPhamDO.SanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

			DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = new DataTable();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dt = ds.Tables[0];
            }
            return dt;
        }
		
      
        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsSanPhamDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsSanPhamDO objcmsSanPhamDO = new cmsSanPhamDO();
                    if (!Convert.IsDBNull(dr["SanPhamID"]))
                        objcmsSanPhamDO.SanPhamID = Convert.ToInt64(dr["SanPhamID"]);
                    if (!Convert.IsDBNull(dr["MaSanPham"]))
                        objcmsSanPhamDO.MaSanPham = Convert.ToString(dr["MaSanPham"]);
                    if (!Convert.IsDBNull(dr["TenSanPham"]))
                        objcmsSanPhamDO.TenSanPham = Convert.ToString(dr["TenSanPham"]);
                    if (!Convert.IsDBNull(dr["MoTaChiTiet"]))
                        objcmsSanPhamDO.MoTaChiTiet = Convert.ToString(dr["MoTaChiTiet"]);
                    if (!Convert.IsDBNull(dr["Mota"]))
                        objcmsSanPhamDO.MoTaChiTiet = Convert.ToString(dr["Mota"]);
                    if (!Convert.IsDBNull(dr["BaoHanh"]))
                        objcmsSanPhamDO.BaoHanh = Convert.ToString(dr["BaoHanh"]);
                    if (!Convert.IsDBNull(dr["LoaiSanPhamID"]))
                        objcmsSanPhamDO.LoaiSanPhamID = Convert.ToInt32(dr["LoaiSanPhamID"]);
                    if (!Convert.IsDBNull(dr["NhanHieuID"]))
                        objcmsSanPhamDO.NhanHieuID = Convert.ToInt32(dr["NhanHieuID"]);
                    if (!Convert.IsDBNull(dr["TuKhoa"]))
                        objcmsSanPhamDO.TuKhoa = Convert.ToString(dr["TuKhoa"]);
                    if (!Convert.IsDBNull(dr["HinhAnh"]))
                        objcmsSanPhamDO.HinhAnh = Convert.ToString(dr["HinhAnh"]);
                    if (!Convert.IsDBNull(dr["DonGia"]))
                        objcmsSanPhamDO.DonGia = Convert.ToInt64(dr["DonGia"]);
                    if (!Convert.IsDBNull(dr["GiamGia"]))
                        objcmsSanPhamDO.GiamGia = Convert.ToInt64(dr["GiamGia"]);
                    if (!Convert.IsDBNull(dr["SanPhamMoi"]))
                        objcmsSanPhamDO.SanPhamMoi = Convert.ToBoolean(dr["SanPhamMoi"]);
                    if (!Convert.IsDBNull(dr["SanPhamBanChay"]))
                        objcmsSanPhamDO.SanPhamBanChay = Convert.ToBoolean(dr["SanPhamBanChay"]);
                    if (!Convert.IsDBNull(dr["DonViID"]))
                        objcmsSanPhamDO.DonViID = Convert.ToInt32(dr["DonViID"]);
                    arrcmsSanPhamDO.Add(objcmsSanPhamDO);
                    if (!Convert.IsDBNull(dr["XuatXuID"]))
                        objcmsSanPhamDO.XuatXuID = Convert.ToInt32(dr["XuatXuID"]);
                }
            }
            return arrcmsSanPhamDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectAllBanChay()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_GetAllBanChay1";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectAllNew(int i)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            if (i == 0)
                Sqlcomm.CommandText = "spcmsSanPham_GetAllNew";
            else
                Sqlcomm.CommandText = "spcmsSanPham_GetAllBanChay";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectByi(int i, int id)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            if (i == 0)
                Sqlcomm.CommandText = "sp_cmsSanPham_GetByNhanHieu";
            else
                Sqlcomm.CommandText = "sp_cmsSanPham_GetByLoaiSP";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@id", SqlDbType.BigInt);
            Sqlparam.Value = id;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectByLoaiSPAndNhanHieu(int loai, int nhanhieu)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_cmsSanPham_GetByLoaiSPAndNhanHieu";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@loai", SqlDbType.Int);
            Sqlparam.Value = loai;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@nh", SqlDbType.Int);
            Sqlparam.Value = nhanhieu;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        //public DataTable SelectAllBanChay()
        //{

        //    SqlCommand Sqlcomm = new SqlCommand();
        //    Sqlcomm.CommandType = CommandType.StoredProcedure;
        //    Sqlcomm.CommandText = "spcmsSanPham_GetAllBanChay1";

        //    DataSet ds = base.GetDataSet(Sqlcomm);
        //    DataTable dt = null;

        //    if (ds != null && ds.Tables.Count > 0)
        //    {
        //        dt = ds.Tables[0];

        //    }
        //    return dt;
        //}

        public DataTable SelectByLoaiSanPhamID(int LoaiSanPhamID)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_cmsSanPham_GetByLoaiSPID";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = LoaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectBySanPhamID(int SanPhamID)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_SelectBySanPhamID";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@SanPhamID", SqlDbType.BigInt);
            Sqlparam.Value = SanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        public DataTable TimKiem(string keyword)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_SearchByName";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Keyword", SqlDbType.NVarChar);
            Sqlparam.Value = keyword;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectbyTagItem(string Tag)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_SelectByTuKhoa";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@TuKhoa", SqlDbType.NVarChar);
            Sqlparam.Value = Tag;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SelectAllbyLoaiSanPhamID(int LoaiSanPhamID)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_SelectByLoaiSanPhamID";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@LoaiSanPhamID", SqlDbType.Int);
            Sqlparam.Value = LoaiSanPhamID;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectbyNhanHieuID(int NhanHieuID)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSanPham_SelectByNhanHieuID";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@NhanHieuID", SqlDbType.Int);
            Sqlparam.Value =  NhanHieuID;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        #endregion

    }

}
